package com.hjy.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.hjy.common.result.Type;
import com.hjy.mapper.TypesMapper;
import com.hjy.service.TypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.convert.TypeMapper;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
public class TypeServiceImpl implements TypeService {
    @Autowired
    private TypesMapper typesMapper;
    @Autowired
    private StringRedisTemplate stringRedisTemplate;
    /**
     * 商品分类
     */
    @Override
    public List<Type> typeList() {
        List<Type> list = typesMapper.typeList();
        list.forEach(type -> {
            stringRedisTemplate.opsForValue().set("type:" + type.getTypeId(), JSONObject.toJSONString(type));
        });

        return list;

    }


}
